package com.android.rest;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class PostalCodeSearchActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        layout.setLayoutParams(params);

        TextView label = new TextView(this);
        label.setText("Enter the zip code");
        label.setMaxHeight(100);
        label.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        label.setGravity(Gravity.CENTER);
        label.setTextColor(this.getResources().getColor(R.color.white));

        final EditText searchField = new EditText(this);
        searchField.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
        searchField.setMaxHeight(100);
        searchField.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        searchField.setGravity(Gravity.LEFT);
        searchField.setTextColor(this.getResources().getColor(R.color.white));
        searchField.requestFocus();

        Button searchButton = new Button(this);
        searchButton.setText("Search");
        searchButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(PostalCodeSearchActivity.this, RESTfulWebServicesActivity.class);
                i.putExtra(PostalCodeSearchActivity.this.getString(R.string.zip), searchField.getText().toString());
                startActivity(i);
            }
        });

        layout.addView(label);
        layout.addView(searchField);
        layout.addView(searchButton);

        this.setContentView(layout);
    }
}